import hec.heclib.dss.HecDss as HecDss
import Tools 
import LogUtils

## Config
#=======================================================

jython_dss_install_path = 'C:/jython2.5.2_hecdss'

beginFutureYR = 2050
beginPastYR = 1940
endPastYR = 1956
totalYR = 5

inDssPath   = 'dss/OriginalSV.dss'
outDssPath  = 'dss/ShiftedSV.dss'

TableTemplatePath  = 'lookup/wytypes.template'
studyTemplatePath = 'run/study.template'

logFilePath = 'PA.log'

#outTablePath_prepend = 'lookup/wytypes_'
#outStudyPath_prepend = 'run/study_'
#=======================================================

## Initialize logging

logger = LogUtils.initLogging(logFilePath)

## Copy historical data ( 5 years sequentially) to future

Tools.cleanDssCatalog(inDssPath)

inFile =  HecDss.open(inDssPath)
outFile = HecDss.open(outDssPath) 

for pastYR in range( beginPastYR, endPastYR ):
       
    Tools.copyDssToFuture(inFile, outFile, pastYR, totalYR, beginFutureYR)

inFile.close()
outFile.close()


## Copy historical water-pastYR types to future

inTable = open(TableTemplatePath,'r') # read only 
outTablePath_prepend = TableTemplatePath.replace('.template','_')

for pastYR in range( beginPastYR, endPastYR ):
    
    Fpart = str(pastYR) + '_' + str(pastYR + totalYR - 1)

    outTablePath = outTablePath_prepend + Fpart + '.table'    
    outTable  = open(outTablePath,'w')     
    inTable.seek(0,0) # rewind to beginning of file
        
    Tools.copyWYTypesToFuture(inTable, outTable, pastYR, totalYR, beginFutureYR)
    
    outTable.close()
    
inTable.close()


## Generate sty file

for pastYR in range( beginPastYR, endPastYR ):
    
    Fpart = str(pastYR) + '_' + str(pastYR + totalYR - 1)
    
    outStudyPath_prepend = studyTemplatePath.replace('.template','_')
    outStudyFilePath = outStudyPath_prepend + Fpart + '.sty' 
    
    Tools.generateStudyFile(studyTemplatePath, outStudyFilePath, Fpart)

